﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Controls;

using HA.ModFlow.Domain.DomainLayer;

using HA.ModFlow.Controls;

using HA.ModFlow.Infrastructure;


namespace HA.ModFlow.Application
{
   public class GlobalMFViewModel:MDTVIViewModel
    {
       public GlobalMFViewModel(MDTVIViewModel parent,GridData grid)
           : base(parent,false)
       {

           this._grid = grid;

           this._imageSource = VMImageSource.globaloption;

           this._isShowCheck = false;


           this._contextMenu = new System.Windows.Controls.ContextMenu();

           MenuItem mi = new MenuItem();

           mi.Command = AppCommands.GlobalOption;

           mi.Header = "属性";

           this._contextMenu.Items.Add(mi);




           this.LoadChildren();


           //添加对应的变化事件
           //this._grid.GridModified += new EventHandler<GridModifiedEventArgs>(_grid_GridModified);

           //this._grid.WaterGrid.WaterGridModified += new EventHandler<WaterGridModifiedEventArgs>(WaterGrid_WaterGridModified);


 
       }

       void WaterGrid_WaterGridModified(object sender, WaterGridModifiedEventArgs e)
       {

           switch (e.Type)
           {
               case WaterGridModifiedType.IBOUND:

                   //所有数据发生变化

                   this.Children.Clear();

                   this.LoadChildren();

                   break;
               case WaterGridModifiedType.INITHEAD:

                   CellCenterDataSet3d head=this._grid.GetIHeadDs();

                   foreach (DSCellCenterDataViewModel item in this.Children)
                   {
                       if (item.Dataset.Label==head.Label)
                       {
                           item.Dataset = head;

                           return;
                           
                       }
                       
                   }




                   break;
               //case WaterGridModifiedType.CONFIEDELEVATION:
               //    break;
               //case WaterGridModifiedType.CONFIEDLAYER:
               //    break;
               default:
                   break;
           }

       }

       void _grid_GridModified(object sender, GridModifiedEventArgs e)
       {
           switch (e.Type)
           {
               case GridModifiedType.ELEVATION:

                   CellCenterDataSet3d top = this._grid.GetTopElevationDs();

                   CellCenterDataSet3d bot = this._grid.GetBotElevationDs();


                   foreach (DSCellCenterDataViewModel item in this.Children)
                   {
                       if (item.Dataset.Label==top.Label)
                       {
                           item.Dataset = top;
                           
                       }

                       if (item.Dataset.Label==bot.Label)
                       {
                           item.Dataset = bot;


                           
                       }
                       
                   }

                   break;
               //case GridModifiedType.ROWCOORDS:
               //    break;
               //case GridModifiedType.COLCOORDS:
               //    break;
               //case GridModifiedType.CROSSPOINTMOVE:
               //    break;
               //default:
               //    break;
           }
          
       }



       public override System.Windows.Input.ICommand DoubleClickCommand
       {
           get
           {
               return AppCommands.GlobalOption;
           }
       }


       GridData _grid;

       protected override void LoadChildren()
       {


           ///生成 top bot inithead ibound子项
           ///

           TopElevationMFViewModel top = new TopElevationMFViewModel(this, this._grid);

           this.Children.Add(top);


           BootElevationMFViewModel bot = new BootElevationMFViewModel(this,this._grid);

           this.Children.Add(bot);

          


           IniHeadMFViewModel head = new IniHeadMFViewModel(this,this._grid);


           this.Children.Add(head);

           IBoundMFViewModel bound = new IBoundMFViewModel(this,this._grid);
           this.Children.Add(bound);





           //CellCenterDataSet3d dsTop =this._grid.GetTopElevationDs();
         


           //CellCenterDataSet3d dsBot =this._grid.GetBotElevationDs();


           //CellCenterDataSet3d dsHead = this._grid.GetIHeadDs();


           //CellCenterDataSet3d dsBound = this._grid.GetIBoundDs();
          



           //DSCellCenterDataViewModel topVM = new DSCellCenterDataViewModel(this,dsTop);

           //this.Children.Add(topVM);


           //DSCellCenterDataViewModel botVM = new DSCellCenterDataViewModel(this,dsBot);
           //this.Children.Add(botVM);



           //DSCellCenterDataViewModel headVm = new DSCellCenterDataViewModel(this,dsHead);

           //this.Children.Add(headVm);


           //DSCellCenterDataViewModel boundVm = new DSCellCenterDataViewModel(this,dsBound);

           //this.Children.Add(boundVm);




       }

       public override string Desc
       {
           get
           {
               return "全局选项";
           }
       }


       protected override void OnSelectedChanged()
       {
           if (this.IsSelected)
           {

               UIModule.DefaultModule.RibbonV2ViewModel.ViewOpViewModel.ToolVM.CurrentTool = APPTOOLMODE.GRID3D;

           }
       }

    }
}
